package com.d0327.homework;

import java.util.Scanner;

public class SortTest {
    public static void main(String[] args) {
        double a = 0;
        String b = null;
        double c = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入想要进行累加的数（退出请输入‘exit’）：");
        while (true) {
            boolean flag = true;
            try {
                b = sc.next();
                a = Double.parseDouble(b);//把字符串b转换为double
            } catch (Exception e) {
                flag = false;
                if (b.equals("exit")) {
                    break;//退出
                } else {
                    System.out.println("输入格式错误，请重新输入");
                }
            }
            if (flag == true) {
                c = c + a;
            }
        }
        System.out.println("结果为：" + c);
    }
}
